<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *评价管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'全部列表'),
	array('op'=>'list1','title'=>'待审核'),
	array('op'=>'list2','title'=>'审核通过'),
	array('op'=>'list3','title'=>'审核不通过'),
	array('op'=>'edit','title'=>'虚拟评价'),
);
$return['checked']=array('0'=>'未审核','1'=>'已审核');
//评价
if($_RQ['op']=='list'){
	$params=array('merchid'=>$_SESSION['onemerchid']);
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','mid','nickname','headimg','level','goodsid','logid','logno','content','images','checked','time');
	$list=pdo_getslice('jy_creditshop_comment',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
				$item['member']=cfc('core')->member_show($item['mid']);
				$item['title']=pdo_getcolumn('jy_creditshop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']),'title');
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'logno','title'=>'参与记录编号','type'=>'string'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'checked','title'=>'审核状态','type'=>'radio','options'=>'checked'),
			array('name'=>'time','title'=>'评价时间','type'=>'time'),
		)),
		'search_one'=>array('name'=>'title','title'=>'商品名称','add'=>false),
		
	);
	$return['checked']=array('0'=>'待审核','1'=>'审核通过','2'=>'审核不通过');
	$return['cstatus']=array('0'=>'未评价','1'=>'已评价');
	$return['rstatus']=array('0'=>'未回复','1'=>'已回复');
	$return['htmls']=$htmls;
	exi($return);
}
//待审核
if($_RQ['op']=='list1'){
	$params=array('merchid'=>$_SESSION['onemerchid']);
	$params['uniacid']=$_SESSION['uniacid'];
	$params['checked']=0;
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','mid','nickname','headimg','level','goodsid','logid','logno','content','images','checked','time');
	$list=pdo_getslice('jy_creditshop_comment',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
				$item['title']=pdo_getcolumn('jy_creditshop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']),'title');
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'logno','title'=>'参与记录编号','type'=>'string'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'time','title'=>'评价时间','type'=>'time'),
		)),
		'search_one'=>array('name'=>'title','title'=>'商品名称','add'=>false),
		
	);
	$return['cstatus']=array('0'=>'未评价','1'=>'已评价');
	$return['rstatus']=array('0'=>'未回复','1'=>'已回复');
	$return['htmls']=$htmls;
	exi($return);
}

//审核通过
if($_RQ['op']=='list2'){
	$params=array('merchid'=>$_SESSION['onemerchid']);
	$params['uniacid']=$_SESSION['uniacid'];
	$params['checked']=1;
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','mid','nickname','headimg','level','goodsid','logid','logno','content','images','checked','time');
	$list=pdo_getslice('jy_creditshop_comment',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
				$item['title']=pdo_getcolumn('jy_creditshop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']),'title');
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'logno','title'=>'参与记录编号','type'=>'string'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'time','title'=>'评价时间','type'=>'time'),
		)),
		'search_one'=>array('name'=>'title','title'=>'商品名称','add'=>false),
		
	);
	$return['cstatus']=array('0'=>'未评价','1'=>'已评价');
	$return['rstatus']=array('0'=>'未回复','1'=>'已回复');
	$return['htmls']=$htmls;
	exi($return);
}
//审核不通过
if($_RQ['op']=='list3'){
	$params=array('merchid'=>$_SESSION['onemerchid']);
	$params['uniacid']=$_SESSION['uniacid'];
	$params['checked']=2;
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','mid','nickname','headimg','level','goodsid','logid','logno','content','images','checked','time');
	$list=pdo_getslice('jy_creditshop_comment',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['title']=pdo_getcolumn('jy_creditshop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']),'title');
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'logno','title'=>'参与记录编号','type'=>'string'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'time','title'=>'评价时间','type'=>'time'),
		)),
		'search_one'=>array('name'=>'title','title'=>'商品名称','add'=>false),
		
	);
	$return['cstatus']=array('0'=>'未评价','1'=>'已评价');
	$return['rstatus']=array('0'=>'未回复','1'=>'已回复');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array(
				'content'=>trim($post['content']),	
				'checked'=>trim($post['checked']),	
		);
		if($post['id']){
			pdo_update('jy_creditshop_comment',$data,array('id'=>$post['id']));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['mid']=$post['mid'];
			$data['goodsid']=$post['goodsid'];
			$data['time']=TIMESTAMP;
			pdo_insert('jy_creditshop_comment',$data);
		}
		exi('提交成功','','list');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_creditshop_comment',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));		
		$item['title']=pdo_getcolumn('jy_creditshop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']),'title');
		$edit=array(
			array('name'=>'content','title'=>'评价内容','type'=>'text'),
			array('name'=>'checked','title'=>'审核状态','type'=>'radio','options'=>'checked'),
			//array('name'=>'time','title'=>'评价时间','type'=>'time'),
		);
	}else{
		$item=array();
		$edit=array(
			array('type'=>'choose','action'=>'/comment/getgoods/','name'=>'goodsid','title'=>'评价商品ID'),
			array('type'=>'choose','title'=>'选择会员','name'=>'mid','action'=>'core/member.get_member//','choose_title'=>'选择会员','help'=>'这里建议选择虚拟会员！不会显示真实会员！'),
			array('name'=>'content','title'=>'评价内容','type'=>'text'),
			array('name'=>'checked','title'=>'审核状态','type'=>'radio','options'=>'checked'),
		);
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'tabs'=>$tabs,
		'edit'=>$edit,		
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_creditshop_comment',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}